package com.ipartek.pruebas.bbdd;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestMySql {
	
	
	static final String DRIVER  = "com.mysql.jdbc.Driver";
	static final String CON_URL = "jdbc:mysql://localhost/sakila";
	static final String USER    = "root";
	static final String PASS    = "admin";
	
	static Connection con = null;
	static ResultSet rs = null;
	static Statement st = null;

	public TestMySql() {
		
	}
	
	public static void main(String[] args) {
		
		
		try{
			
			con = DriverManager.getConnection( CON_URL, USER , PASS);
			System.out.println("establecida la conexion a MySQL BBDD=" + CON_URL);
			
			st = con.createStatement();
			
			rs = st.executeQuery("SELECT * FROM city");
			while (rs.next())
			{
				System.out.print(rs.getString(1) + " ");
				System.out.print(rs.getString(2) + " ");
				System.out.print(rs.getString(3) + " ");
				System.out.println(rs.getString(4));		
			}
			rs.close();
			st.close();
			con.close();
			
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		
		
	}
	

}
